/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import pojo.User;
import pojo.User;
import util.HibernateUtil;

/**
 *
 * @author OSIRIS
 */
public class UserDAO extends AbstractDAO{
 public static List<User> getList() throws HibernateException{
        List<User> ds=null;
        Session session=HibernateUtil.getSessionFactory().openSession();
       
            
            String hql="select sp from User sp";
            Query query=session.createQuery(hql);
            ds=query.list();
       
        
        return ds;
        
        
    }
 public static List Login(String mail,String pass) throws HibernateException{
      List<User> ds=null;
        Session session=HibernateUtil.getSessionFactory().openSession();
       
            
            String hql="select us from User us where us.email like:mail and us.matKhau=:pass";
            Query query=session.createQuery(hql);
            query.setString("mail",mail);
            query.setString("pass",pass);
            ds=query.list();
       
        
        return ds;
     
 }
   public UserDAO() {
        super();
    }

    /**
     * Insert a new User into the database.
     * @param info
     */
    public void create(User info) throws DataAccessLayerException {
        super.saveOrUpdate(info);
    }


    /**
     * Delete a detached User from the database.
     * @param info
     */
    public void delete(User info) throws DataAccessLayerException {
        super.delete(info);
    }

    /**
     * Find an User by its primary key.
     * @param id
     * @return
     */
    public User find(Integer id) throws DataAccessLayerException {
        return (User) super.find(User.class, id);
    }

    /**
     * Updates the state of a detached User.
     *
     * @param info
     */
    public void update(User info) throws DataAccessLayerException {
        super.saveOrUpdate(info);
    }

    /**
     * Finds all Users in the database.
     * @return
     */
    public List findAll() throws DataAccessLayerException{
        return super.findAll(User.class);
    }
}
